﻿using Sundry.BLL;
using Sundry.IBLL;
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sundry.App_Start.Common
{
    public class SelectItemHelper
    {

        #region 获取上传图片水印类型列表
        /// <summary>
        /// 获取上传图片水印类型列表
        /// </summary>
        /// <param name="watermarkType">当前水印类型值，无时传0</param>
        /// <returns>图片水印类型列表</returns>
        public static IEnumerable<SelectListItem> WatermarkType(int watermarkType)
        {
            List<SelectListItem> itemList = new List<SelectListItem>();
            foreach (int item in Enum.GetValues(typeof(Sundry.Model.WatermarkType)))
            {
                itemList.Add(new SelectListItem()
                {
                    Selected = item == watermarkType ? true : false,
                    Value = item.ToString(),
                    Text = Enum.GetName(typeof(Sundry.Model.WatermarkType), item)
                });
            }
            return itemList;
        } 
        #endregion

        #region 获取图片上传水印位置列表
        /// <summary>
        /// 获取图片上传水印位置列表
        /// </summary>
        /// <param name="watermarkPosition">当前位置，无时传0</param>
        /// <returns>水印位置列表</returns>
        public static IEnumerable<SelectListItem> WatermarkPosition(int watermarkPosition)
        {
            List<SelectListItem> itemList = new List<SelectListItem>();
            foreach (int item in Enum.GetValues(typeof(Sundry.Model.WatermarkPosition)))
            {
                itemList.Add(new SelectListItem()
                {
                    Selected = item == watermarkPosition ? true : false,
                    Value = item.ToString(),
                    Text = Enum.GetName(typeof(Sundry.Model.WatermarkPosition), item)
                });
            }
            return itemList;
        } 
        #endregion

        #region 获取文字字体列表
        /// <summary>
        /// 获取文字字体列表
        /// </summary>
        /// <param name="watermarkTextFont">当前文字字体</param>
        /// <returns>文字字体列表</returns>
        public static IEnumerable<SelectListItem> FontList(string watermarkTextFont)
        {
            InstalledFontCollection fontList = new InstalledFontCollection();
            List<SelectListItem> itemList = fontList.Families.Select(family => new SelectListItem() { Text = family.Name, Value = family.Name, Selected = family.Name == watermarkTextFont ? true : false }).ToList();
            return itemList;
        } 
        #endregion

        #region 获取管理权限列表
        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <param name="nowAuthoryId">当前权限ID</param>
        /// <returns>权限列表</returns>
        public static IEnumerable<SelectListItem> AuthoryList(int nowAuthoryId)
        {
            IServiceEntrace _serviceEntrace = new ServiceEntrace();
            List<SelectListItem> itemList = new List<SelectListItem>() { 
            new SelectListItem(){ Selected=true, Text="请选择权限", Value="0"}
            };
            ;
            itemList.AddRange(_serviceEntrace.GetAuthoryService.LoadEntities().Select(m => new { m.AuthoryId, m.Name }).ToList().Select(m => new SelectListItem() { Value = m.AuthoryId.ToString(), Text = m.Name, Selected = m.AuthoryId == nowAuthoryId ? true : false }));
            return itemList;
        }
        #endregion
    }
}